package org.demo.hdfs.tools;

import java.net.URI;

import org.apache.hadoop.fs.FileSystem;
import org.demo.hdfs.config.FusionHadoopProperties;

public class HadoopTools {

	public static FileSystem fileSystem() {
		FileSystem fileSystem = null;
		FusionHadoopProperties fusionHadoopProperties = SpringBeanTool.getBean(FusionHadoopProperties.class);
		try {
			String url = fusionHadoopProperties.getUrl();
			url = "hdfs://" + url;
			String username = fusionHadoopProperties.getUsername();
			org.apache.hadoop.conf.Configuration configurationhadoop = new org.apache.hadoop.conf.Configuration();
			String replication = fusionHadoopProperties.getReplication();
			if(replication!=null && replication.trim().length() > 0) {
				configurationhadoop.set("dfs.replication", replication);	
			}
			fileSystem = FileSystem.get(new URI(url), configurationhadoop, username);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fileSystem;
	}
}
